package com.hnhcyy.goods.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hnhcyy.goods.mapper.SpTestReportMapper;
import com.hnhcyy.goods.pojo.SpTestReport;
import com.hnhcyy.goods.service.SpTestReportAdminService;

/**
 * 质检报告service实现类
 * @author gesh
 */
@Service
public class SpTestReportAdminServiceImpl implements SpTestReportAdminService {
	
	@Autowired
	SpTestReportMapper spTestReportMapper;
	
	public static final ObjectMapper MAPPER = new ObjectMapper();
	
	/**
	 * 查询记录
	 */
	@Override
	public String listSpTestReport(SpTestReport queryParam) {
		
		System.out.println("-=-=-=-" + queryParam.toString());

		List<SpTestReport> list = spTestReportMapper.listSpTestReport(queryParam);

		// 转化为json字符串返回，因为admin端调用用的是原生feign，直接返回List和Mapper会提示解码错误

		String result = "";
		try {
			result = MAPPER.writeValueAsString(list);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

		System.out.println("---->" + result);

		return result;
	}
	
	/**
	 * 插入记录
	 */
	@Override
	public String insertSpTestReport(SpTestReport spTestReport) {
		
		int result = spTestReportMapper.insertSpTestReport(spTestReport);
		return result + "";
	}
	
	/**
	 * 更新记录
	 */
	@Override
	public String updateSpTestReport(SpTestReport spTestReport) {
		
		int updateResult = spTestReportMapper.update(spTestReport);
		
		return updateResult + "";
	}
	
	/**
	 * 删除记录
	 */
	@Override
	public String deleteSpTestReport(Integer fid) {
		
		int deleteResult = spTestReportMapper.delete(fid);
		
		return deleteResult + "";
	}

}
